using UnityEngine;
using System.Collections;
using System.IO.Ports;

public class WinScript : MonoBehaviour {

	public int forceRange = 1;
	public int numObjects = 100;
	public Transform spawn;
	private Controllers controllerScript;
	// Use this for initialization
	void Start () {
		controllerScript = spawn.GetComponent<Controllers>();
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnTriggerEnter(Collider other)
	{
		if(other.tag == "Player")
		{
			Vector3 pos = other.transform.position;
			controllerScript.sp.WriteLine("0");
			Destroy(other.gameObject);
			
			for(int i = 0; i < numObjects; i++)
			{
				GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Cube);
				sphere.transform.localScale = new Vector3(5, 5, 5);
				sphere.transform.position = pos;
				sphere.AddComponent("Rigidbody");
				int force1 = Random.Range(-forceRange, forceRange);
				int force2 = Random.Range(-forceRange, forceRange);
				int force3 = Random.Range(-forceRange, forceRange);
				sphere.transform.rigidbody.AddForce(force1, force2, force3);
			}
		}
	}
}
